<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
    />
    <title>云上大陆-上线即领百元红包</title>
    <script src="//source.szmengqukj.com/page/js/jquery-1.7.2.min.js"></script>
    <script src="//s-sdk.szmengqukj.com/cdn-boot/swiper-bundle.min.js"></script>
    <script src="./flexible.js"></script>
    <link
      rel="stylesheet"
      href="//source.szmengqukj.com/page/css/loadPage.css"
    />
    <link
      rel="stylesheet"
      href="//s-sdk.szmengqukj.com/cdn-boot/swiper-bundle.min.css"
    />
    <link
      rel="stylesheet"
      href="//s-sdk.szmengqukj.com/web/squeeze/style/animate.min.css"
    />
    <link rel="stylesheet" href="./base-css.css" />
  </head>

  <body>
    <div class="container">
      <div class="upper-box">
        <!-- 顶部六要素 -->
        <div class="lysTop">
          <p style="text-align: center; color: white">
            <span class="developer-span" id="lysTop-info"></span>
            <span class="developer-span">&nbsp;|&nbsp;</span>
            <a
              class="app-auth-span"
              href="javascript:;"
              style="color: white; text-decoration: none"
            >
              应用权限
            </a>
            <span class="app-auth-span">&nbsp;|&nbsp;</span>
            <a
              class="privacy-span"
              href="javascript:;"
              style="color: white; text-decoration: none"
            >
              隐私政策
            </a>
          </p>
        </div>

        <!-- 轮播内容 -->
        <div class="swiper-box">
          <div class="swiper mySwiper swiper-no-swiping">
            <div class="swiper-wrapper">
              <div class="swiper-slide">
                <img
                  src="//s-sdk.szmengqukj.com/web/squeeze/icon-notice@2x.png"
                />
                <span class="swiper-slide-text1"
                  >恭喜qqq刚刚抽中了华为手机</span
                >
              </div>
              <div class="swiper-slide">
                <img
                  src="//s-sdk.szmengqukj.com/web/squeeze/icon-notice@2x.png"
                />
                <span class="swiper-slide-text1"
                  >恭喜aaa刚刚抽中了华为手机</span
                >
              </div>
            </div>
          </div>
        </div>

        <!-- 抽奖模块 -->
        <div id="sudoku_container" class="sudoku_container">
          <div id="prize_box" class="prize_box"></div>
          <div id="sudoku_btn" class="lottery-btn">
            <img
              id="sudoku_btn_img"
              src="//s-sdk.szmengqukj.com/web/squeeze/img24_24/Lottery-button1.png"
            />
          </div>
        </div>

        <!-- 活动说明 -->
        <div id="rule-box" class="activity-desc">
          <div class="activity-desc-title">
            <img
              src="//s-sdk.szmengqukj.com/web/squeeze/activity-left-dot@2x.png"
            />
            <div>活动说明</div>
            <img
              src="//s-sdk.szmengqukj.com/web/squeeze/activity-right-dot@2x.png"
            />
          </div>
          <div class="activity-desc-content">
            活动时间：<br />
            即日起-2023年12月30日<br />
            活动内容：<br />
            活动期间，用户可以再快手APP平台活动页参与抽奖活动。<br />
            活动中奖概率高达100%，奖品内容包括：苹果手机、华为手机、现金红包等。<br />
            抽奖规则：<br />
            1、凡是进入活动页的用户都可以免费获得抽奖机会。<br />
            2、抽奖后，用户需要进入知道APP才能领取奖品，未主动领取的视为自动放弃。<br />
            3、此活动解释权归活动发起方所有。<br />
          </div>
        </div>
      </div>

      <!-- 遮罩层 -->
      <div id="mark" class="mark"></div>

      <!-- 中奖弹窗 -->
      <div id="mark-box" class="mark-box">
        <img
          class="mark-box-1 mark-position"
          src="//s-sdk.szmengqukj.com/web/squeeze/img24_24/Winning-Popup.png"
        />
        <div class="mark-content mark-position">
          <img
            class="mark-box-2"
            src="//s-sdk.szmengqukj.com/web/squeeze/img24_24/Winning-window1.png"
          />
          <img id="prize-img" class="mark-prize" src="" />
          <div id="prize-countdown" class="mark-prize-countdown">
            00:59:30内有效
          </div>
          <div id="prize-name" class="mark-prize-name"></div>
        </div>
        <div class="mark-go">
          <img
            class="mark-box-3"
            src="//s-sdk.szmengqukj.com/web/squeeze/img24_24/Claim-button.png"
          />
          <div class="mark-go-text">
            立即打开APP参与活动
            <img src="//s-sdk.szmengqukj.com/web/squeeze/icon-next@2x.png" />
          </div>
        </div>
      </div>

      <!-- 返回弹窗 -->
      <div id="back-box" class="back-box">
        <img
          class="back-box-1 back-position"
          src="//s-sdk.szmengqukj.com/web/squeeze/new-popup.png"
        />
        <img id="back-prize-img" class="back-prize" src="" />
        <div id="back-name" class="back-prize-name"></div>
        <div id="click-down" class="click-down"></div>
        <div id="close-back-box" class="close-back-box">×</div>
      </div>
    </div>
  </body>

  <script>
    let time = 1;
    let timer = null;
    let drawTimer = null; // 启动抽奖定时器
    const sequenceIds = [0, 1, 2, 4, 7, 6, 5, 3]; //抽奖闪烁顺序

    let isShow = false; // 判断是否展示活动规则

    const body = $("body");
    const prize = $("#prize_box"); // 奖品dom
    const lowerBox = $("#rule-box"); // 下盒子

    const mark = $("#mark"); // 遮罩层
    const markBox = $("#mark-box"); // 中奖弹窗
    const prizeImg = $("#prize-img"); // 中奖图片
    const prizeName = $("#prize-name"); // 中奖名字
    const countdown = $("#prize-countdown"); // 倒计时

    const backBox = $("#back-box"); // 返回弹窗
    const backPrizeImg = $("#back-prize-img"); // 返回弹窗，中奖图片
    const backName = $("#back-name");
    const clickDown = $("#click-down");
    const closeBackbox = $("#close-back-box");

    // 抽奖按钮
    const prizeStart = $("#sudoku_btn");
    const prizeBtnImg = $("#sudoku_btn_img");

    // 获取六要素span
    const developerSpan = $(".developer-span"); // 开发者
    const appAuthSpan = $(".app-auth-span"); // 应用权限
    const privacySpan = $(".privacy-span"); // 隐私政策
    const appNameSpan = $(".app-name-span"); // 应用名称
    const appVersionSpan = $(".app-version-span"); // 应用版本
    const appTimeSpan = $(".app-time-span"); // 更新时间

    //奖品列表
    const prizeList = [
      {
        id: 0,
        isAward: false,
        name: "华为手机",
        active: false,
        img: "//s-sdk.szmengqukj.com/web/squeeze/icon@2x(1).png",
      },
      {
        id: 1,
        isAward: false,
        name: "平板电脑",
        active: false,
        img: "//s-sdk.szmengqukj.com/web/squeeze/icon@2x.png",
      },
      {
        id: 2,
        isAward: false,
        name: "蓝牙耳机",
        active: false,
        img: "//s-sdk.szmengqukj.com/web/squeeze/icon@2x(2).png",
      },
      {
        id: 3,
        isAward: false,
        name: "100元红包",
        active: false,
        img: "//s-sdk.szmengqukj.com/web/squeeze/icon@2x(3).png",
      },
      {
        id: 4,
        isAward: false,
        name: "智能手表",
        active: false,
        img: "//s-sdk.szmengqukj.com/web/squeeze/icon@2x(4).png",
      },
      {
        id: 5,
        isAward: false,
        name: "智能电视",
        active: false,
        img: "//s-sdk.szmengqukj.com/web/squeeze/icon@2x(7).png",
      },
      {
        id: 6,
        isAward: false,
        name: "Switch",
        active: false,
        img: "//s-sdk.szmengqukj.com/web/squeeze/icon@2x(5).png",
      },
      {
        id: 7,
        isAward: true,
        name: "200元红包",
        active: false,
        img: "//s-sdk.szmengqukj.com/web/squeeze/icon@2x(6).png",
      },
      {
        id: 8,
        isAward: false,
        name: "",
        img: "",
      },
    ];

    function getUrlParam(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if (r != null) {
        return decodeURIComponent(r[2]);
      }
      return null;
    }
    var paramValue = getUrlParam("channelSaleRecordId");
    console.log("paramValue : >>", paramValue);

    // 监听返回弹窗
    $(function () {
      pushHistory();
      window.addEventListener(
        "popstate",
        function (e) {
          prizeBtnImg.attr(
            "src",
            "//s-sdk.szmengqukj.com/web/squeeze/img24_24/Lottery-button1.png"
          );
          mark.show();
          markBox.hide();

          if (drawTimer < 94) {
            backBox.addClass("animate__animated animate__zoomIn");
          } else {
            backBox.addClass("animate__animated animate__zoomIn");
          }
          backBox.show();

          // clearTimeout(drawTimer);

          window.history.replaceState(
            null,
            null,
            `/sudoku-base/sudoku-squeeze-base.html?channelSaleRecordId=${paramValue}`
          );
        },
        false
      );

      function pushHistory() {
        const state = { title: "title", url: "#" };
        window.history.pushState(state, "title", "#");

        const item = prizeList.find((item) => item.isAward == true);
        backPrizeImg.attr("src", item.img);
        backName.html(item.name);
      }
    });

    mark.hide();
    markBox.hide();
    backBox.hide();

    if (isShow) {
      lowerBox.hide();
    } else {
      lowerBox.show();
    }

    // 排版奖品列表
    function sortPrize(list) {
      let node = "";
      list.forEach((item, index) => {
        if (item.id === 8) {
          node += `<div id="prize_${item.id}"></div>`;
        } else {
          node += `
            <div id="prize_${item.id}" class="row_gift" prize="${item.id}">
              <img id="prize-img_${item.id}" src="${item.img}" />
              <div>${item.name}</div>
            </div>
          `;
        }
      });
      prize.append(node);
    }
    let arr = prizeList.slice(3, 5);
    arr.splice(1, 0, prizeList[prizeList.length - 1]);
    sortPrize(prizeList.slice(0, 3));
    sortPrize(arr);
    sortPrize(prizeList.slice(5, 8));

    function rightSpeed(id) {
      if ([3, 5].includes(id)) {
        return 3;
      } else if ([2, 4, 6, 7].includes(id)) {
        return 7;
      } else {
        return 10;
      }
    }

    /**
     * 抽奖过程动画
     * @param {number} index
     * @param {number} speed 速度
     * @return {void}
     */
    function luckyAnimation(index = 0, speed = 1) {
      let isfun = false;
      time > 8 ? (time += 10) : (time += 0.1);
      time > 40 && (isfun = true);

      drawTimer = setTimeout(() => {
        if (index === 0) {
          prizeList[sequenceIds[sequenceIds.length - 1]].active = false;
        } else {
          prizeList[sequenceIds[index - 1]].active = false;
        }

        prizeList[sequenceIds[index]].active = true;

        prizeList.forEach((item) => {
          const prizeDom = $(`#prize_${item.id}`);
          if (item.active) {
            prizeDom.addClass("row_gift_isactive");
          } else {
            prizeDom.removeClass("row_gift_isactive");
          }
        });

        if (isfun && prizeList[sequenceIds[index]].isAward) {
          //动画结束,发送弹窗事件
          timer = setTimeout(() => {
            const prizeItem = prizeList.find((item) => item.isAward == true);
            prizeImg.attr("src", prizeItem.img);
            prizeName.html(prizeItem.name);
            prizeList[sequenceIds[index]].active = false;
            prizeBtnImg.attr(
              "src",
              "//s-sdk.szmengqukj.com/web/squeeze/lottery-btn2@2x.png"
            );

            mark.show();
            markBox.addClass("animate__animated animate__zoomIn");
            markBox.show();
            backBox.hide();

            countdownTask(3600);
            document.body.style.overflow = "hidden";
          }, 500);

          time = 1;
          isfun = false;
          return;
        }

        index++;
        if (index > 7) index = 0;
        luckyAnimation(index, time);
      }, rightSpeed(prizeList.find((item) => item.isAward == true).id) * speed);
    }

    // 抽奖按钮改变图片
    prizeStart.click((e) => {
      prizeBtnImg.attr(
        "src",
        "//s-sdk.szmengqukj.com/web/squeeze/img24_24/lotterying2.png"
      );
      luckyAnimation();
    });

    // 轮播内容
    var swiper = new Swiper(".mySwiper", {
      direction: "vertical",
      loop: true, // 循环模式选项
      autoplay: {
        delay: 1000,
        stopOnLastSlide: false,
        disableOnInteraction: false,
      },
    });

    /**
     * 渲染倒计时
     * @param {number} downTime 倒计时秒
     * @return {void}
     */
    function countdownTask(downTime) {
      if (downTime === 0) {
        countdown.html("已失效");
        return;
      }
      // 计算剩余时间的小时、分钟和秒数
      var hours = Math.floor((downTime % (60 * 60 * 24)) / (60 * 60));
      var minutes = Math.floor((downTime % (60 * 60)) / 60);
      var seconds = Math.floor(downTime % 60);

      // 更新倒计时显示
      countdown.html(hours + ":" + minutes + ":" + seconds + "内有效");
      setTimeout(() => {
        countdownTask(downTime - 1);
      }, 1000);
    }

    // 点击遮罩层 下载
    mark.click((e) => {
      downLoad();
    });

    // 点击奖品 下载
    markBox.click((e) => {
      downLoad();
    });

    clickDown.click((e) => {
      downLoad();
    });

    function downLoad() {
      console.log(123);
    }

    closeBackbox.click((e) => {
      backBox.hide();
      mark.hide();
    });
  </script>
</html>
